package com.sgb.contract.view.ui.accountdetail;

import android.content.Context;

import androidx.lifecycle.MutableLiveData;

import com.sgb.contract.api.ContractNet;
import com.sgb.contract.base.viewmodel.BaseViewModel;
import com.sgb.contract.test.model.OpenAccountDetailEntity;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import org.jetbrains.annotations.NotNull;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * AccountDetailViewModel
 *
 * @author chentao
 */
public class AccountDetailViewModel extends BaseViewModel {
    public MutableLiveData<OpenAccountDetailEntity> detail = new MutableLiveData<>();

    public void getCompanyDetail(Context context) {
        DialogHelper.showProgressDialog2(context, null, "数据加载中", 0, true, null, false);
        ContractNet.getInstance().getContractApi().getCompanyDetail().enqueue(new Callback<BaseEntity<OpenAccountDetailEntity>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<OpenAccountDetailEntity>> call, @NotNull Response<BaseEntity<OpenAccountDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.isSuccessful() && "ok".equals(response.body().getState())) {
                    detail.setValue(response.body().getData());
                } else {
                    MToast.showToast(context, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<OpenAccountDetailEntity>> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
                MToast.showToast(context, t.getMessage());
            }
        });
    }
}